﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Channels;

namespace ch02.service
{
    class Program
    {
        static void Main(string[] args)
        {
            //Uri[] baseAddresses = new Uri[2];
            //baseAddresses[0] = new Uri("http://127.0.0.1/myservices");
            //baseAddresses[0] = new Uri("net.tcp://127.0.0.1/myservices");
            using (ServiceHost host = new ServiceHost(typeof(CalculatorService)/*,baseAddresses*/))
            {
                Uri uri = new Uri("http://127.0.0.1:8888/myservices");
                AddressHeader header = AddressHeader.CreateAddressHeader("Licensed User", "http://www.wcf-programming.com", "administrator");
                EndpointAddress address = new EndpointAddress(uri, header);
                Binding binding = new WSHttpBinding();
                ContractDescription contract = ContractDescription.GetContract(typeof(contract.ICalculator));
                ServiceEndpoint endpoint = new ServiceEndpoint(contract, binding, address);
                endpoint.ListenUri = new Uri("http://127.0.0.1:9999/myservices");
                endpoint.ListenUriMode = ListenUriMode.Explicit;
                host.AddServiceEndpoint(endpoint);

                //host.AddServiceEndpoint("ch02.service.contract.ICalculator", new WSHttpBinding(), "CalculatorService");
                //host.AddServiceEndpoint("ch02.service.contract.ICalculator", new NetTcpBinding(), "CalculatorService");
                host.Open();
                for (int i = 1; i <= host.ChannelDispatchers.Count; i++)
                {
                    Console.WriteLine("{0}: {1}", i, host.ChannelDispatchers[i - 1].Listener.Uri);
                }
                Console.Read();
            }
        }
    }
}
